In [1]:
name = 'Sam'

In [2]:
name


Out[2]:
'Sam'

In [3]:
# name[0] = 'P'

last_letters = name[1:]

In [4]:
last_letters


Out[4]:
'am'

In [5]:
'P' + last_letters


Out[5]:
'Pam'

In [6]:
x = 'Hello World'

In [7]:
x + 'it is beautiful outside!'


Out[7]:
'Hello Worldit is beautiful outside!'

In [8]:
x = x + ' it is beautiful outside!'

In [9]:
x


Out[9]:
'Hello World it is beautiful outside!'

In [10]:
letter = 'z'

In [11]:
letter*10


Out[11]:
'zzzzzzzzzz'

Difference in operators


In [12]:
2 + 3


Out[12]:
5

In [13]:
'2' + '3'


Out[13]:
'23'

In [14]:
2 * '2' + '3'


Out[14]:
'223'

In [15]:
2 * ('2' + '3')


Out[15]:
'2323'

In [16]:
2 * ('2' + '$' + '3' + '£')


Out[16]:
'2$3£2$3£'

In [17]:
2 * ('2' + '£' + '3' + '$') * 6


Out[17]:
'2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$'

In [18]:
2 * ('2' + '£' + '3' + '$') + 6


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-7024a6658d27> in <module>()
----> 1 2 * ('2' + '£' + '3' + '$') + 6

TypeError: must be str, not int

In [19]:
2 * ('2' + '£' + '3' + '$') * 6


Out[19]:
'2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$2£3$'

In [20]:
x = 'Hidie Hi'

In [21]:
x.capitalize()


Out[21]:
'Hidie hi'

In [22]:
x.casefold()


Out[22]:
'hidie hi'

In [23]:
x.count(x)


Out[23]:
1

In [24]:
x = 'Hidie Hi'

In [25]:
x


Out[25]:
'Hidie Hi'

In [26]:
x.count(x)


Out[26]:
1

In [27]:
x.encode()


Out[27]:
b'Hidie Hi'

In [28]:
x.endswith('die ho')


Out[28]:
False

In [29]:
x.endswith('i')


Out[29]:
True

In [30]:
x.find('e')


Out[30]:
4

In [31]:
x.index('i')


Out[31]:
1

In [32]:
x.isalpha()


Out[32]:
False

In [33]:
x.isdigit()


Out[33]:
False

In [34]:
x.upper()


Out[34]:
'HIDIE HI'

In [35]:
x


Out[35]:
'Hidie Hi'

In [36]:
x.swapcase()


Out[36]:
'hIDIE hI'

In [37]:
x.replace('i', 'a')


Out[37]:
'Hadae Ha'

In [38]:
x.split()


Out[38]:
['Hidie', 'Hi']

In [39]:
x = 'Hi this is a string a ling a ding ding thing i write first in thin things.'

In [40]:
x.split('i')


Out[40]:
['H',
 ' th',
 's ',
 's a str',
 'ng a l',
 'ng a d',
 'ng d',
 'ng th',
 'ng ',
 ' wr',
 'te f',
 'rst ',
 'n th',
 'n th',
 'ngs.']

x.(press tab for string functions of x) this is only for notebook. Functions can be found elsewhere.


In [ ]: